package com.david.common.comtext;

import com.david.system.mapper.UserMapper;
import com.david.system.pojo.Entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

public class UserContext implements AutoCloseable{
    static final ThreadLocal<UserEntity> ctx = new ThreadLocal<>();

    public UserContext(UserEntity user){
        ctx.set(user);
    }
    public static UserEntity currentUser(){
        return ctx.get();
    }
    @Override
    public void close() throws Exception {
        ctx.remove();
        System.out.println("ThreadLocal close ---------");
    }
}
